//
//  RecommendTableViewCell.m
//  ZZLC
//
//  Created by 杨春至 on 2017/12/13.
//  Copyright © 2017年 ZhongZeng. All rights reserved.
//

#import "RecommendTableViewCell.h"

@interface RecommendTableViewCell ()

@property (nonatomic,strong) UIImageView *typeImageView;

@property (nonatomic,strong) UILabel *typeLb;

@property (nonatomic,strong) UILabel *numLb;

@property (nonatomic,strong) UILabel *profitLb;

@property (nonatomic,strong) UILabel *desLb;

@property (nonatomic,strong) UILabel *DayAndMoneyLb;

@property (nonatomic,strong) UILabel *restCoutnLb;

@property (nonatomic,strong) UIView *lineView;

@property (nonatomic,strong) UIImageView *rewardImageView;

@property (nonatomic,strong) UILabel *rewardLb;

@end

@implementation RecommendTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self configUI];
    }
    return self;
}
- (void)configUI{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    UIView *contentView = self.contentView;
    [contentView addSubview:self.typeImageView];
    [contentView addSubview:self.typeLb];
    [contentView addSubview:self.numLb];
    [contentView addSubview:self.profitLb];
    [contentView addSubview:self.desLb];
    [contentView addSubview:self.DayAndMoneyLb];
    [contentView addSubview:self.restCoutnLb];
    [contentView addSubview:self.lineView];
    [self sendSubviewToBack:_lineView];
    [contentView addSubview:self.rewardImageView];
    [self.rewardImageView addSubview:self.rewardLb];
}
- (void)setModel:(ProduceModel *)model{
    _model = model;
    _typeImageView.image = [model.type integerValue]==1?UIImageMake(@"newPlayer"):UIImageMake(@"recommendPlayer");
    _typeLb.text = model.tips;
    _numLb.text = model.title;
    _profitLb.text = [NSString stringWithFormat:@"%@ %@",model.baseEarnings,@"%"];
    _desLb.text = model.label2;
    _DayAndMoneyLb.text = model.label1;
    _restCoutnLb.text = model.label3;
    _rewardLb.text = [NSString stringWithFormat:@"+%@ %@",model.jiangLi,@"%"];
    if ([model.jiangLi floatValue]<=0) {
        _rewardImageView.hidden = YES;
    }
}
- (void)layoutSubviews{
    CGFloat gap = 15;
    [_typeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.top.equalTo(self);
        make.height.equalTo(@(109/2));
        make.width.equalTo(@(163/2));
    }];
    [_typeLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_typeImageView.mas_right).offset(gap);
        make.centerY.equalTo(_typeImageView);
        make.height.equalTo(@14);
        make.width.equalTo(@(KWidth - _typeImageView.right-gap*2));
    }];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self);
        make.bottom.equalTo(_typeImageView.mas_bottom);
        make.height.equalTo(@0.4);
        make.right.equalTo(self);
    }];
    
    [_numLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.top.equalTo(_typeImageView.mas_bottom).offset(gap);
        make.width.equalTo(_typeLb);
        make.height.equalTo(_typeLb);
    }];
    [_profitLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.top.equalTo(_numLb.mas_bottom).offset(gap);
        make.width.equalTo(_typeLb);
        make.height.equalTo(@20);
    }];
    [_desLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(@(gap));
        make.top.equalTo(_profitLb.mas_bottom).offset(gap);
        make.width.equalTo(_typeLb);
        make.height.equalTo(@13);
    }];
    [_DayAndMoneyLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_centerX);
        make.centerY.equalTo(_profitLb.mas_centerY);
        make.width.equalTo(_typeLb);
        make.height.equalTo(@15);
    }];
    [_restCoutnLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_DayAndMoneyLb);
        make.centerY.equalTo(_desLb.mas_centerY);
        make.width.equalTo(_typeLb);
        make.height.equalTo(@13);
    }];
    [_rewardImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_typeImageView.mas_right);
        make.bottom.equalTo(_profitLb.mas_centerY);
        make.height.equalTo(@(45.0/2));
        make.width.equalTo(@(40));
    }];
    [_rewardLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_equalTo(UIEdgeInsetsMake(-7, 0, 0, 0));
    }];
}
- (UIImageView *)typeImageView{
    if (!_typeImageView) {
        _typeImageView = [UIImageView new];
//        _typeImageView.contentMode = UIViewContentModeLeft;
        _typeImageView.image = UIImageMake(@"newPlayer");
    }
    return _typeImageView;
}
- (UILabel *)typeLb{
    if (!_typeLb) {
        _typeLb = [UILabel new];
        _typeLb.font = [UIFont systemFontOfSize:13];
        _typeLb.textColor = [UIColor blackColor];
        _typeLb.text = @"限购1次，T+1 起息";
    }
    return _typeLb;
}
- (UILabel *)numLb{
    if (!_numLb) {
        _numLb = [UILabel new];
        _numLb.font = [UIFont systemFontOfSize:13];
        _numLb.textColor = [UIColor blackColor];
        _numLb.text = @"新手专享No.1138";
    }
    return _numLb;
}
- (UILabel *)profitLb{
    if (!_profitLb) {
        _profitLb = [UILabel new];
        _profitLb.font = [UIFont systemFontOfSize:19];
        _profitLb.textColor = ZZGoldColor;
        _profitLb.text = @"15.00%";
    }
    return _profitLb;
}
- (UILabel *)desLb{
    if (!_desLb) {
        _desLb = [UILabel new];
        _desLb.font = [UIFont systemFontOfSize:14];
        _desLb.textColor = [UIColor grayColor];
        _desLb.text = @"预期年变化收益";
    }
    return _desLb;
}
- (UILabel *)DayAndMoneyLb{
    if (!_DayAndMoneyLb) {
        _DayAndMoneyLb = [UILabel new];
        _DayAndMoneyLb.font = [UIFont systemFontOfSize:14];
        _DayAndMoneyLb.textColor = [UIColor blackColor];
        _DayAndMoneyLb.text = @"15天 | 100元";
    }
    return _DayAndMoneyLb;
}
- (UILabel *)restCoutnLb{
    if (!_restCoutnLb) {
        _restCoutnLb = [UILabel new];
        _restCoutnLb.font = [UIFont systemFontOfSize:13];
        _restCoutnLb.textColor = [UIColor grayColor];
        _restCoutnLb.text = @"剩余金额33.88万元";
    }
    return _restCoutnLb;
}
- (UIView *)lineView{
    if (!_lineView) {
        _lineView = [UIView new];
        _lineView.backgroundColor = [UIColor qmui_colorWithHexString:@"#dfdfdf"];
    }
    return _lineView;
}
- (UIImageView *)rewardImageView{
    if (!_rewardImageView) {
        _rewardImageView = [UIImageView new];
        _rewardImageView.image = UIImageMake(@"reword");
    }
    return _rewardImageView;
}
- (UILabel *)rewardLb{
    if (!_rewardLb) {
        _rewardLb = [UILabel new];
        _rewardLb.textColor = [UIColor whiteColor];
        _rewardLb.font = [UIFont systemFontOfSize:10];
        _rewardLb.textAlignment = NSTextAlignmentCenter;
    }
    return _rewardLb;
}

@end
